//
//  FillRepairInfomationViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/29.
//

import UIKit
import CollectionKit
import RxCocoa
import RxSwift

class FillRepairInfomationViewController: UIViewController {

  var collectionView = CollectionView()

  let disposeBag = DisposeBag()

  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    setupTreeView()

    bindingObserver()
  }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension FillRepairInfomationViewController {

  func setupTreeView() {

    opacityNavigationBar()

    view.backgroundColor = .designKit.background
    view.addSubview(collectionView)

    collectionView.snp.makeConstraints { maker in
      maker.edges.equalToSuperview()
        .inset(UIEdgeInsets(top: 0, left: 0, bottom: 88, right: 0))
    }
  }

  func bindingObserver() {

    title = "填写报修信息"

    let headerProvider = SimpleViewProvider(
        views: [
          R.nib.friStatusContentView(owner: nil)!
        ],
        sizeStrategy: (.fill, .absolute(108))
    )

    let selectDataSource = ArrayDataSource<String>(data:[
      "", "", "", "", "", ""
    ])

    let selectViewSource = ClosureViewSource<String, SelectItemContentView> { data, index in
      return R.nib.selectItemContentView(owner: nil)!
    } viewUpdater: { item, data, index in

    }

    let selectSizeSource = { (index: Int, data: String, size: CGSize) in
        return CGSize(
          width: (size.width - 44) / 2,
          height: 34
        )
    }

    let selectProvider = BasicProvider<String, SelectItemContentView>(
      dataSource: selectDataSource,
      viewSource: selectViewSource,
      sizeSource: selectSizeSource,
      layout: FlowLayout(spacing: 12, justifyContent: .spaceEvenly)
        .inset(by: UIEdgeInsets(top: 12, left: 0, bottom: 16, right: 0))
    )

    selectProvider.tapHandler = { (context) in

    }


    let descriptionProvider = SimpleViewProvider(
        views: [
          R.nib.friInputInfomationContentView(owner: nil)!
        ],
        sizeStrategy: (.fill, .absolute(182))
    )

    let dataSource = ArrayDataSource<String>(data:[
      "我的通知"
    ])

    let viewSource = ClosureViewSource<String, AddImageContentView> { data, index in
      return R.nib.addImageContentView(owner: nil)!
    } viewUpdater: { item, data, index in

    }

    let sizeSource = { (index: Int, data: String, size: CGSize) in
        return CGSize(
          width: (size.width - 16 * 4) / 3,
          height: (size.width - 16 * 4) / 3
        )
    }

    let itemProvider = BasicProvider<String, AddImageContentView>(
      dataSource: dataSource,
      viewSource: viewSource,
      sizeSource: sizeSource,
      layout: FlowLayout(spacing: 16)
        .inset(by: UIEdgeInsets(top: 12, left: 0, bottom: 16, right: 0))
    )

    itemProvider.tapHandler = { (context) in

    }

    let contactProvider = SimpleViewProvider(
        views: [
          R.nib.friContactInformationContentView(owner: nil)!
        ],
        sizeStrategy: (.fill, .absolute(268))
    )

    collectionView.provider = ComposedProvider(
//        layout: FlowLayout(lineSpacing:32),
        sections: [
          headerProvider,
          selectProvider,
          descriptionProvider,
          itemProvider,
          contactProvider
        ]
    )

    let bottomView = R.nib.friBottomFeeContentView(owner: self)!

    view.addSubview(bottomView)
    bottomView.snp.makeConstraints({ make in
      make.left.right.bottom.equalToSuperview()
      make.height.equalTo(88)
    })

//    bottomView.completeTap.subscribe(onNext: {
//
//    })
//    .disposed(by: disposeBag)
  }
}
